package com.tarena.security.admin.controller;

import com.tarena.security.admin.entity.db.Strategy;
import com.tarena.security.admin.entity.db.UserRole;
import com.tarena.security.admin.param.StrategyParam;
import com.tarena.security.admin.param.UpdateStrategyParam;
import com.tarena.security.admin.param.UpdateUserRoleParam;
import com.tarena.security.admin.param.UserRoleParam;
import com.tarena.security.admin.result.JsonResult;
import com.tarena.security.admin.service.IStrategyService;
import com.tarena.security.admin.service.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 策略表格 前端控制器
 * </p>
 *
 * @author Ly
 * @since 2023-04-10
 */
@RestController
@Api(tags = "策略表格控制器")
@RequestMapping("/strategy")
@Slf4j
public class StrategyController {

    @Autowired
    IStrategyService strategyService;
    // 添加策略
    @ApiOperation("新增策略")
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated StrategyParam strategyParam){
        log.info("收到前端的strategyParam:{}",strategyParam);
        strategyService.insertOne(strategyParam);
        return JsonResult.ok();
    }

    // 查询策略
    @ApiOperation("查询策略")
    @PostMapping("/select-strategy")
    public JsonResult<Strategy> selectById(Integer Id){
        log.info("userId:{}",Id);
        Strategy s=strategyService.selectOne(Id);
        log.info("u:{}",s);
        return JsonResult.ok(s);
    }

    // 删除用户角色
    @ApiOperation("删除策略")
    @PostMapping("/delete-strategy")
    public JsonResult<Void> deleteById(Integer Id){
        log.info("userId:{}",Id);
        strategyService.deteleOneById(Id);
        return JsonResult.ok();
    }

    // 修改策略
    @ApiOperation("修改策略")
    @PostMapping("/update-strategy")
    public JsonResult<Void> updateByuserRole(@Validated UpdateStrategyParam updateStrategyParam){
        log.info("UserRoleParam:{}",updateStrategyParam);
        int num=strategyService.updateByStrategy(updateStrategyParam);
        return JsonResult.ok();
    }

}
